package com.sise.thread.lab01.lab03;


import java.util.concurrent.atomic.AtomicInteger;

//具有原子性的一个类测试
public class VolatileAtom extends Thread{
    public volatile static int count=0;
    public AtomicInteger atomicInteger=new AtomicInteger(0);

    @Override
    public void run(){
        for(int i=0;i<1000;i++){
//            atomicInteger.incrementAndGet();
            count++;
        }
//        System.out.println(getName()+atomicInteger.get());
        System.out.println(getName()+count);
    }

    public static void main(String[] args) {
        VolatileAtom volatileAtom[]=new VolatileAtom[10];
        for (int j=0;j<volatileAtom.length;j++) {
            VolatileAtom atom=new VolatileAtom();
            volatileAtom[j]=atom;
        }
        for (VolatileAtom atom : volatileAtom) {
            atom.start();
        }
    }
}
